home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Files / Locations / Directory.cp < prev    next >
Text File  |  2000-06-23  |  1KB  |  67 lines

  1. // Directory.cp
  2.  
  3. #ifndef Directory_h
  4. #include "Directory.h"
  5. #endif
  6. #ifndef CatInfo_h
  7. #include "CatInfo.h"
  8. #endif
  9. #ifndef NotADirectoryError_h
  10. #include "NotADirectoryError.h"
  11. #endif
  12. #ifndef DirectoryNotFoundError_h
  13. #include "DirectoryNotFoundError.h"
  14. #endif
  15.  
  16. #include <Errors.h>
  17.  
  18. void Directory::Up()
  19.   {
  20.     Assert( !IsRoot() );
  21.     CatInfo info( *this );
  22.     id = info.Location().ParentID();
  23.   }
  24.  
  25. void Directory::Down( ConstPString name )
  26.   {
  27.     CatInfo info( *this, name );
  28.  
  29.     if ( !info.IsDirectory() )
  30.         throw NotADirectoryError( noErr );
  31.     
  32.     volume = info.Location().Volume();
  33.     id = info.Directory().ID();
  34.   }
  35.  
  36. Directory Directory::Parent() const
  37.   {
  38.     Assert( !IsRoot() );
  39.     CatInfo info( *this );
  40.     return info.Location().Parent();
  41.   }
  42.  
  43. Directory Directory::FindSpecialFolder( OSType folder,
  44.                                                      ::Volume volume,
  45.                                                      bool canCreate )
  46.   {
  47.     int16 volumeFound;
  48.     int32 directoryFound;
  49.     OSErr error = FindFolder( volume.RefNum(),
  50.                                       folder,
  51.                                       canCreate,
  52.                                       &volumeFound,
  53.                                       &directoryFound );
  54.     
  55.     switch ( error )
  56.       {
  57.         case fnfErr:    throw DirectoryNotFoundError( error );
  58.         case dupFNErr:    throw NotADirectoryError( error );
  59.       }
  60.     
  61.     if ( error != noErr )
  62.         throw FileError( error );
  63.      
  64.     return Directory( ::Volume( volumeFound ),
  65.                             DirectoryID( directoryFound ) );
  66.   }
  67.